package com.taxi.driver.module.main.mine.help;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.qianxx.adapter.OnClickListener;
import com.taxi.driver.R;
import com.taxi.driver.common.Application;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.module.main.mine.help.dragger.DaggerHelpCenterComponent;
import com.taxi.driver.module.main.mine.help.dragger.HelpCenterModule;
import com.taxi.driver.module.vo.FaqVO;
import com.taxi.driver.util.Navigate;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 帮助中心
 */
public class HelpCenterActivity extends BaseActivity implements HelpCenterContract.View, OnClickListener {
    @BindView(R.id.recycler_view)
    RecyclerView recycler_view;

    @Inject
    HelpCenterPresenter mPresenter;
    FaqAdapter adapter;
    LinearLayoutManager linearLayoutManager;
//        String currentCity;
        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_center);
        ButterKnife.bind(this);

        DaggerHelpCenterComponent.builder()
                .appComponent(Application.getAppComponent())
                .helpCenterModule(new HelpCenterModule(this))
                .build().inject(this);

        linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycler_view.setLayoutManager(linearLayoutManager);
        adapter = new FaqAdapter(this);
        recycler_view.setAdapter(adapter);
        recycler_view.setNestedScrollingEnabled(false);
        adapter.setOnItemClickListener(this);
        mPresenter.reqFAQs();
//            currentCity=new SP(this).getString("city","");

    }

    @OnClick({R.id.rl_contact_customer_service, R.id.rl_advice_feedback})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_contact_customer_service:
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getResources().getString(R.string.contact_phone)));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.rl_advice_feedback:
                Navigate.openFeedback(HelpCenterActivity.this);
                break;
        }
    }

    @Override
    public boolean isActive() {
        return false;
    }

//    @Override
//    public void getCurrentCity(String city) {
//        currentCity=city;
//    }

    @Override
    public void showFAQs(List<FaqVO> faqs) {
        if (faqs != null && faqs.size() > 0) {
            adapter.clear();
            adapter.addAll(faqs);
        }
    }

    /**
     * 联系客服
     */
//    public void customerService() {
//        if (currentCity.equals("天津市")){
//            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getResources().getString(R.string.contact_phone)));
//            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            startActivity(intent);
//        }else{
//            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + getResources().getString(R.string.contact_phone_other)));
//            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            startActivity(intent);
//        }
//
//    }

    @Override
    public void onClick(int position, View view, Object item) {
        Navigate.openProblem(this, ((FaqVO) item));
    }
}
